// JavaScript Document
define(
    function(require) {
        function EllipseO() {
            this.type = 'ellipseo';
        }

        EllipseO.prototype =  {
            /**
             * 创建圆形路径
             * @param {Context2D} ctx Canvas 2D上下文
             * @param {Object} style 样式
             */
            buildPath : function(ctx, style) {

				ctx.font = '14px sans-serif'; 

				//BezierEllipse2(ctx, 33,21,30,18);
				BezierEllipse2(ctx, style.x, style.y, style.a, style.b);
				function BezierEllipse2(ctx, x, y, a, b)
				{
				   var k = .5522848,
				   ox = a * k, // 水平控制点偏移量
				   oy = b * k; // 垂直控制点偏移量
				   ctx.lineWidth = 3;
				   //从椭圆的左端点开始顺时针绘制四条三次贝塞尔曲线
				   ctx.moveTo(x - a, y);
				   ctx.bezierCurveTo(x - a, y - oy, x - ox, y - b, x, y - b);
				   ctx.bezierCurveTo(x + ox, y - b, x + a, y - oy, x + a, y);
				   ctx.bezierCurveTo(x + a, y + oy, x + ox, y + b, x, y + b);
				   ctx.bezierCurveTo(x - ox, y + b, x - a, y + oy, x - a, y);
				}
				return;
            },
			drift : function(e, dx, dy) {
				e.style.x += dx;
				e.style.y += dy;
			},
			isCover : function(e, x, y) {
				if(goFlow.judge.lineDrag || goFlow.judge.updating || goFlow.judge.choiceMoving) {
					return false;	
				}
				if (x >= (e.style.x - e.style.a / 2 - 10)&& x <= (e.style.x + e.style.a / 2 + 10)&& (y >= e.style.y - e.style.b / 2 - 10)&& (y <= (e.style.y + e.style.b / 2 + 10))) {
					return true;
				}
				return false;
			},
			 /**
             * 返回矩形区域，用于局部刷新和文字定位
             * @param {Object} style
             */
            getRect : function(style) {
                var lineWidth;
                if (style.brushType == 'stroke' || style.brushType == 'fill') {
                    lineWidth = style.lineWidth || 1;
                }
                else {
                    lineWidth = 0;
                }
                return {
                    x : Math.round(style.x - style.a - lineWidth / 2),
                    y : Math.round(style.y - style.b - lineWidth / 2),
                    width : style.a * 2 + lineWidth,
                    height : style.b * 2 + lineWidth
                };
            }
        };

        var base = require('./base');
        base.derive(EllipseO);
        
        var shape = require('../shape');
        shape.define('ellipseo', new EllipseO());
        return EllipseO;
    }
);